package com.untrance.shop.core.builder.vo;

import com.untrance.shop.common.vo.CommentVO;
import com.untrance.shop.model.Comment;
import com.untrance.shop.model.User;

/**
 * @author eugene zadyra
 */
public class CommentVOBuilder extends AbstractVOBuilder<Comment, CommentVO> {

	private User user;

	public CommentVOBuilder(User user) {
		this.user = user;
	}

	@Override
	protected CommentVO transform(Comment comment) {
		CommentVO commentVO = new CommentVO();
		commentVO.setMessage(comment.getMessage());
		if (user != null) {
			commentVO.setUserName(user.getUsername());
		}
		if (comment.getTimeAdded() != null) {
			commentVO.setDate(comment.getTimeAdded().toString());
		}
		return commentVO;
	}
}
